<?php

namespace App\Admin\Service;

use App\Admin\Grid\NGrid;
use App\Models\AuditModel;
use Encore\Admin\Grid\Filter;

class AuditService extends BaseService
{
    public string $table = 'audit';

    /**
     * grid
     * @param string $type
     * @return void
     */
    public function grid(string $type): void
    {
        $this->grid = new NGrid(new AuditModel);
        $this->grid->model()->leftJoin('shop_user', 'shop_user.user_id', 'audit.user_id')
            ->leftJoin('user_dm', 'user_dm.user_id', 'shop_user.user_id')
            ->where('audit.type', $type)->where('audit.status', 0)
            ->select('audit.*', 'shop_user.user_mobile', 'user_dm.real_name');
        $this->filter();
        $this->gid();
    }

    /**
     * filter
     * @return void
     */
    public function filter(): void
    {
        $this->grid->filter(function (Filter $filter) {
            $filter->disableIdFilter();
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('id', 'ID');
                $filter->equal('user_mobile', $this->l['userMobile']);
            });
            $filter->column(1 / 2, function (Filter $filter) {
                $filter->equal('serial_number', $this->l['serialNumber']);
            });
        });
    }
}
